package com.woniuxy.credit_loans.collection_zhang.service.Impl;

import com.woniuxy.credit_loans.collection_zhang.service.BorrowService;
import com.woniuxy.credit_loans.collection_zhang.vo.BorrowEchartsVo;
import com.woniuxy.credit_loans.entity.Borrow;
import com.woniuxy.credit_loans.mapper.BorrowMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;

@Service
public class BorrowServiceImpl implements BorrowService {


    @Autowired
    private BorrowMapper borrowMapper;

    @Override
    public List<BorrowEchartsVo> selectTypeEcharts() {
         List<BorrowEchartsVo> borrowEchartsVos = borrowMapper.selectTypeEcharts();
        return borrowEchartsVos;
    }

    @Override
    public List<Borrow> selectyuan() {
         List<Borrow> selectyuan = borrowMapper.selectyuan();
         return  selectyuan;
    }

    @Override
    public List<BorrowEchartsVo> selectEcharts() {
         List<BorrowEchartsVo> borrowEchartsVos = borrowMapper.selectEcharts();
            return  borrowEchartsVos;
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        borrowMapper.deleteByPrimaryKey(id);
        return 0;
    }

    @Override
    @Transactional
    public List<Borrow> selectAll(String input) {
        List<Borrow> list=borrowMapper.selectAll(input);

        for (Borrow borrow:list) {

            Borrow borrow1=new Borrow();
            BigDecimal borrowMoney = borrow.getBorrowMoney();
            borrow1.setBorrowMoney(borrowMoney);
           borrow1.setBorrowType(borrow.getBorrowType());
           borrow1.setBorrowId(borrow.getBorrowId());
           borrowMapper.updateByPrimaryKeySelective(borrow1);
        }
        return  list;
    }

    @Override
    public int insertSelective(Borrow record) {
        borrowMapper.insertSelective(record);
        return 0;
    }

    @Override
    public Borrow selectByPrimaryKey(Long id) {
        Borrow borrow=borrowMapper.selectByPrimaryKey(id);
        return borrow;
    }

    @Override
    public int updateByPrimaryKeySelective(Borrow record) {
        borrowMapper.updateByPrimaryKeySelective(record);
        return 0;
    }
}
